package com.yanqu.road.server.cmd.marriage;

import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.entity.servercenter.group.CrossMarriageGroup;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.marriage.CrossGroupMarriageMgr;
import com.yanqu.road.server.manger.CrossMarriageGroupMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_MARRIAGE_GET_APPOINT_LIST, desc = "获取跨服指向联姻列表")
public class CrossMarriageGetAppointListCmd extends CrossCommand {
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossMarriageGroup marriageGroup = CrossMarriageGroupMgr.getCrossMarriageGroupByServerId(serverId);
        if(!CrossMarriageGroupMgr.canCrossMarriage(marriageGroup)){
            return;
        }
        List<MarriageInfo> marriageInfoList = CrossGroupMarriageMgr.getAppointApply(marriageGroup.getGroupId(), serverId, userId);
        MarriageProto.MarriageApplyListMsg.Builder listMsg = MarriagePb.parseMarriageApplyListMsg(marriageInfoList);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_CROSS_MARRIAGE_APPOINT_APPLY_LIST, listMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
